package com.ybfenpan.servlet;


import com.ybfenpan.model.Member;
import com.ybfenpan.utils.ContextUtil;
import com.ybfenpan.utils.StringUtil;
import com.ybfenpan.utils.SysConst;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class AuthInterceptor implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object object) throws Exception {
		Member member = ContextUtil.getMember();
		if("App".equals(request.getParameter("fm"))){
			String code = request.getParameter("code");
			if(StringUtil.isNotBlank(code)){
				//user = new User();
				//在sessino会话中存储用户所有信息
				request.getSession().setAttribute(SysConst.MEMBER, member);
			}
		}
		if(null == member){
			response.sendRedirect(request.getContextPath()+"/index.jsp");
			return false;
		}
		return true;
	}
	
	@Override
	public void afterCompletion(HttpServletRequest request,
                                HttpServletResponse response, Object object, Exception arg3)
			throws Exception {
		 
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response,
                           Object object, ModelAndView modelAndView) throws Exception {
		
	}
	

}
